﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Frame.Lib.Core.Tree;
using Frame.Lib.Utilities;

public partial class Common_TreeDlg : PageSelectTree
{
    private TreeBO<TreeInfo> _tree;

    protected void Page_Load(object sender, EventArgs e)
    {
        string tableName = Request["TableName"];
        _tree = new TreeBO<TreeInfo>(tableName);
        if (!IsPostBack)
        {
            string strSingleSelect = Request["SingleSelect"];
            
            if (Request["Title"] != null)
            {
                lblTitle.Text = Request["Title"];
            }
            //if (strSingleSelect != null && strSingleSelect != "")
            //{
            //    bool flag = bool.Parse(strSingleSelect);
            //    if (flag)
            //    {
            //        tvList.Attributes.Add("onclick", "SingleSelect()");
            //    }
            //}
            //else
            //{
            //    tvList.Attributes.Add("onclick", "MultiSelect()");
            //}
            BindTree();
            
        }
    }

    

    private void BindTree()
    {
        List<int> lstSelectIDs = StrUtil.SplitToInt(RestoreIDs);
        //_tree.BindTreeView(tvList, true, lstSelectIDs);

        IEnumerable<TreeInfo> list = _tree.GetList(); 
        StringBuilder sb = new StringBuilder();

        foreach (TreeInfo info in list)
        {
            sb.Append("{ id: " + info.ID + ", pId: " + info.UpperID + ", name: '" + info.Name + "'");

            if (info.UpperID == 0)
            {
                sb.Append(",open:true");
            }

            sb.Append("},");
        }

        lblJson.Text = sb.ToString().TrimEnd(',');
    }
}
